package npda;

import pda.PDAConfiguration;
import pda.Stack;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author haoly
 * @title NPDADesign
 * @date 2025/4/22 10:33
 * @description TODO
 */
public class NPDADesign<T> {
    private final T startState;

    private final Character bottomCharacter;

    private final Set<T> acceptStates;

    private final NPDARulebook rulebook;

    public NPDADesign(T startState, Character bottomCharacter, Set<T> acceptStates, NPDARulebook rulebook) {
        this.startState = startState;
        this.bottomCharacter = bottomCharacter;
        this.acceptStates = new HashSet<>(acceptStates);
        this.rulebook = rulebook;
    }

    public Boolean accepts(String s){
        NPDA<T> npda = toNPDA();
        npda.readString(s);
        return npda.accepting();

    }

    private NPDA<T> toNPDA() {
        Stack<Character> startStack = new Stack<>(Arrays.asList(bottomCharacter));
        PDAConfiguration<T> startConfig = new PDAConfiguration<>(startState, startStack);
        return new NPDA<>(Set.of(startConfig), acceptStates, rulebook);
    }
}
